package com.hoshiicloud.shxping.feign;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hoshiicloud.common.query.OmnipotentWrapper;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.saleorder.dto.OrderDTO;
import com.hoshiicloud.saleorder.entity.Consultations;
import com.hoshiicloud.saleorder.entity.OrderInfo;
import com.hoshiicloud.saleorder.entity.OrderMain;
import com.hoshiicloud.saleorder.entity.RefundOrder;
import com.hoshiicloud.saleorder.param.*;
import com.hoshiicloud.saleorder.param.OrderInfoQueryParam;
import com.hoshiicloud.saleorder.param.OrderInfoUpdateParam;
import com.hoshiicloud.saleorder.param.OrderMainQueryParam;
import com.hoshiicloud.saleorder.param.RefundOrderPayParam;
import com.hoshiicloud.saleorder.param.refund.RefundOrderListParam;
import com.hoshiicloud.saleorder.param.refund.RefundOrderPageParam;
import com.hoshiicloud.saleorder.vo.refund.RefundOrderVo;
import com.hoshiicloud.shxping.dto.PayResultDTO;
import com.hoshiicloud.shxping.feign.hystrix.HystrixOrderFeignFallback;
import com.hoshiicloud.shxping.param.*;
import com.hoshiicloud.shxping.param.OrderMainStatusUpdateParam;
import com.hoshiicloud.shxping.param.OrderQueryParam;
import com.hoshiicloud.shxping.param.OrderSubmitParam;
import com.hoshiicloud.shxping.param.PayOrderParam;
import com.hoshiicloud.shxping.param.StoreOrderQueryParam;
import com.hoshiicloud.shxping.vo.CartDetailVO;
import com.hoshiicloud.shxping.vo.CartVO;
import com.hoshiicloud.shxping.vo.GoodsBrowseRecordDetailVO;
import com.hoshiicloud.shxping.vo.GoodsBrowseRecordVO;
import com.hoshiicloud.user.entity.store.PlatStore;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author yangcheng
 * @version 1.0
 * @title: OrderFeignService
 * @description: 订单微服务FeignClient
 * @date 2019/6/10 0:40
 * @mail maiboyc@163.com
 */
@FeignClient(name = "hoshiicloud-sale-order", fallbackFactory = HystrixOrderFeignFallback.class)
public interface OrderFeignService {

    // 提交订单
    @RequestMapping(value = "/saleorder/biz/submitOrder", method = RequestMethod.POST)
    Response submitOrder(@RequestBody OrderSubmitParam param);

    // 支付订单
    @RequestMapping(value = "/saleorder/biz/payOrder", method = RequestMethod.POST)
    Response<PayResultDTO> payOrder(@RequestBody PayOrderParam param);

    // 取消订单
    @RequestMapping(value = "/saleorder/biz/cancelOrder", method = RequestMethod.POST)
    Response cancelOrder(@RequestBody @Valid Long orderId);

    // 批量取消订单
    @RequestMapping(value = "/saleorder/biz/batchCancelOrder", method = RequestMethod.POST)
    Response batchCancelOrder(@RequestBody List<Long> orderIds);

    // 退款订单
    @RequestMapping(value = "/saleorder/biz/refundOrder", method = RequestMethod.POST)
    Response refundOrder(@RequestBody RefundOrderPayParam param);

    // 删除订单
    @RequestMapping(value = "/saleorder/biz/deleteOrder", method = RequestMethod.POST)
    Response deleteOrder(@RequestBody @Valid Long orderId);

    // 分页订单列表
    @RequestMapping(value = "/saleorder/biz/listOrder", method = RequestMethod.POST)
    Response<Page<OrderDTO>> listOrder(@RequestBody OrderQueryParam param);

    // 所有订单列表
    @RequestMapping(value = "/saleorder/biz/listAllOrders", method = RequestMethod.POST)
    Response<List<OrderDTO>> listAllOrders(@RequestBody OrderQueryParam param);

    // 订单详情
    @RequestMapping(value = "/saleorder/biz/viewOrder", method = RequestMethod.POST)
    Response<OrderDTO> viewOrder(@RequestBody Long orderId);

    // 核销订单
    @RequestMapping(value = "/saleorder/biz/verificationOrder", method = RequestMethod.POST)
    Response verificationOrder(@RequestBody Long orderId);

    // 核销订单
    @RequestMapping(value = "/saleorder/biz/verificationBatchOrder", method = RequestMethod.POST)
    Response verificationBatchOrder(@RequestBody OrderMainIdsUpdateParam param);

    // 店铺订单列表（按创建时间排序）
    @RequestMapping(value = "/saleorder/biz/listStoreOrder", method = RequestMethod.POST)
    Response<Page<OrderDTO>> listStoreOrder(@RequestBody StoreOrderQueryParam param);

    // 店铺订单列表（按提货时间排序）
    @RequestMapping(value = "/saleorder/biz/listStoreOrderByDeliveryTime", method = RequestMethod.POST)
    Response<Page<OrderDTO>> listStoreOrderByDeliveryTime(@RequestBody StoreOrderQueryParam param);

    // 店铺可提货订单列表（按提货时间排序）
    @RequestMapping(value = "/saleorder/biz/listCanPickUpStoreOrder", method = RequestMethod.POST)
    Response<List<OrderMain>> listCanPickUpStoreOrder(@RequestBody StoreOrderQueryParam param);

    // 根据时间段查询已经付款待自提的订单
    @RequestMapping(value = "/saleorder/biz/listCanPickUpOrderWithTime", method = RequestMethod.POST)
    Response<List<OrderMain>> listCanPickUpOrderWithTime(@RequestBody StoreOrderQueryParam param);

    // 更新订单状态
    @RequestMapping(value = "/saleorder/biz/verificationOrder/update", method = RequestMethod.POST)
    Response<OrderDTO> updateOrderStatus(@RequestBody OrderMainStatusUpdateParam param);

    // 查询商品购买记录
    @RequestMapping(value = "/saleorder/biz/queryOrdersWithUserInfo", method = RequestMethod.POST)
    Response<Page<Map<String, Object>>> queryOrdersWithUserInfo(@RequestBody OrderQueryParam param);

    // 查询主订单信息
    @RequestMapping(value = "/saleorder/order-main/list", method = RequestMethod.POST)
    Response<List<OrderMain>> listOrderMainInfos(@RequestBody OrderMainQueryParam param);

    //根据主订单ID查询主订单
    @GetMapping("/saleorder/order-main/{id}")
    Response<OrderMain> getOrderMainById(@PathVariable("id") Long id);


    // 查询子订单信息
    @RequestMapping(value = "/saleorder/order-info/list", method = RequestMethod.POST)
    Response<List<OrderInfo>> listOrderInfos(@RequestBody OrderInfoQueryParam param);

    /**
     * 根据扩展spu主键组查询销售数量
     *
     * @param spuIds 扩展spu主键组
     * @return Response<List < Map < String, Object>>>
     */
    @RequestMapping("/saleorder/order-info/selectSalesCountBySpuIds")
    Response<List<Map<String, Object>>> selectSalesCountBySpuIds(@RequestParam("spuIds") List<Long> spuIds, @RequestParam("status") Integer status);

    /**
     * 根据总店分组查询已售数量
     *
     * @param status 订单状态
     * @return List<Map < String, Object>>
     */
    @RequestMapping("/saleorder/order-info/selectSalesCountGroupByStorePid")
    Response<List<Map<String, Object>>> selectSalesCountGroupByStorePid(@RequestParam("status") Integer status);

    /**
     * 按店铺分组获取店铺粉丝数和购买指数
     *
     * @param status 订单状态
     * @return List<Map < String, Object>>
     */
    @RequestMapping("/saleorder/order-info/getStoreFansAndBuyExponentGroupById")
    Response<List<Map<String, Object>>> getStoreFansAndBuyExponentGroupById(@RequestParam("status") Integer status);

    //根据子订单ID查询子订单
    @GetMapping("/saleorder/order-info/{id}")
    Response<OrderInfo> getOrderInfoById(@PathVariable("id")  Long id);

    //根据子订单ID查询子订单
    @PutMapping("/saleorder/order-info/update")
    Response<Boolean> updateOrderInfoById(@RequestBody OrderInfoUpdateParam orderInfoParam);

    /**
     * @Author qry
     * @Date 16:43 2019/9/2
     * 根据子订单id集合获取子订单信息
     **/
    @GetMapping("/saleorder/order-info/getByIds")
    Response<List<OrderInfo>> getOrderInfoByIds(@RequestParam("ids") List<Long> ids);

    /**
     * 新增购物车购物信息
     *
     * @param param 加入购物车参数
     * @return Response
     */
    @RequestMapping(value = "/customer/cart/add", method = RequestMethod.POST)
    Response add(@RequestBody CartAddParam param);

    /**
     * 修改购物车购物信息
     *
     * @param param 更新购物车参数
     * @return Response
     */
    @RequestMapping(value = "/customer/cart/update", method = RequestMethod.POST)
    Response update(@RequestBody CartUpdateParam param);

    /**
     * 更新购物车商品失效状态
     *
     * @param userId 用户ID
     * @return Response
     */
    @RequestMapping(value = "/customer/cart/checkCart", method = RequestMethod.POST)
    Response updateCartStatus(@RequestParam("userId") String userId);

    /**
     * 删除购物车购物信息记录表
     *
     * @param id 购物车ID
     * @return Response
     */
    @RequestMapping(value = "/customer/cart/delete", method = RequestMethod.POST)
    Response delete(@RequestParam("id") String id);

    /**
     * 根据用户ID和店铺ID批量删除购物车购物信息
     *
     * @param userId  用户ID
     * @param storeId 店铺ID
     * @return Response
     */
    @RequestMapping(value = "/customer/cart/deleteByUserIdAndStoreId", method = RequestMethod.DELETE)
    Response deleteByUserIdAndStoreId(@RequestParam("userId") Long userId, @RequestParam("storeId") Long storeId);

    /**
     * 批量删除购物车购物信息记录表
     *
     * @param ids 购物车IDS
     * @return Response
     */
    @RequestMapping(value = "/saleorder/cart/deleteByIds", method = RequestMethod.POST)
    Response deleteByIds(@RequestParam("ids") List<Long> ids);

    /**
     * 获取购物车购物信息详情
     *
     * @param id 主键ID
     * @return Response<CartDetailVO>
     */
    @RequestMapping(value = "/customer/cart/getDetail", method = RequestMethod.GET)
    Response<CartDetailVO> getDetail(@RequestParam("id") String id);

    /**
     * 获取购物车购物信息列表
     *
     * @param param 查询参数
     * @return Response<List < CartVO>>
     */
    @RequestMapping(value = "/customer/cart/getList", method = RequestMethod.POST)
    Response<List<CartVO>> getList(@RequestBody CartQueryParam param);

    /**
     * 分页获取购物车购物信息列表
     *
     * @param param 分页参数
     * @return Response<IPage < CartVO>>
     */
    @RequestMapping(value = "/customer/cart/getPage", method = RequestMethod.POST)
    Response<Page<CartVO>> getPage(@RequestBody CartQueryParam param);

    /**
     * 新增商品浏览记录
     *
     * @param param 新增参数
     * @return Response
     */
    @RequestMapping(value = "/customer/goods-browse-record/add", method = RequestMethod.POST)
    Response add(@RequestBody GoodsBrowseRecordAddParam param);

    /**
     * 获取商品浏览记录列表
     *
     * @param param 查询参数
     * @return Response<List < GoodsBrowseRecordVO>>
     */
    @RequestMapping(value = "/customer/goods-browse-record/getList", method = RequestMethod.POST)
    Response<List<GoodsBrowseRecordVO>> getGoodsBrowseList(@RequestBody GoodsBrowseRecordQueryParam param);

    /**
     * 获取商品浏览记录详情
     *
     * @param id 浏览记录ID
     * @return Response<GoodsBrowseRecordDetailVO>
     */
    @RequestMapping(value = "/customer/goods-browse-record/getDetail", method = RequestMethod.GET)
    Response<GoodsBrowseRecordDetailVO> getGoodsBrowseDetail(@RequestParam("id") String id);

    /**
     * 根据spuIds查询商品浏览记录
     *
     * @param spuIds 扩展spu主键集合
     * @return Response<List < Map < Long, Object>>>
     */
    @RequestMapping(value = "/customer/goods-browse-record/getListBySpuIds", method = RequestMethod.GET)
    Response<List<Map<String, Object>>> selectFocusCountBySpuIds(@RequestParam("spuIds") List<Long> spuIds);

    /**
     * 获取商品浏览记录根据基础spu分组
     *
     * @return Response<List < Map < String, Object>>>
     */
    @RequestMapping(value = "/customer/goods-browse-record/getListGroupByBaseSpuId", method = RequestMethod.GET)
    Response<List<Map<String, Object>>> selectFocusCountGroupByBaseSpuId();


    /**
     * @Author qry
     * @Date 10:21 2019/8/28
     * 新增退款单
     **/
    @PostMapping(value = "/refund/refund-order/save")
    Response<RefundOrder> saveRefundOrder(@RequestBody RefundOrder entity);


    /**
     * @Author qry
     * @Date 10:22 2019/8/28
     * 更新退款单
     **/
    @PutMapping("/refund/refund-order/update")
    Response<Boolean> updataRefundOrderById(@RequestBody RefundOrder entity);


    /**
     * @Author qry
     * @Date 10:35 2019/8/28
     * 根据退款单ID 查询退款单
     **/
    @GetMapping("/refund/refund-order/{id}")
    Response<RefundOrder> getRefundOrderById(@PathVariable("id") Long id);

    @PostMapping("/refund/refund-order/list")
    Response<List<RefundOrderVo>> listRefundOrder(@RequestBody RefundOrderListParam param);

    @PostMapping("/refund/refund-order/getPage")
    Response<Page<RefundOrderVo>> pageRefundOrder(@RequestBody RefundOrderPageParam param);

    @PostMapping("/refund/refund-order/omniRefundOrder")
    Response<List<RefundOrder>> omniRefundOrder(@RequestBody List<OmnipotentWrapper> wrappers);

    /**
     * @Author qry
     * @Date 10:22 2019/8/28
     * 新增退款协商历史
     **/
    @PostMapping(value = "/refund/consultations/save")
    Response<Consultations> saveConsultations(@RequestBody Consultations entity);

    /**
     * @Author qry
     * @Date 10:46 2019/8/28
     * 物理删除 退款协商历史的系统记录 （删除旧的 插入新的）
     **/
    @DeleteMapping("/refund/consultations/physicsDelete/{refundId}")
    Response<Boolean> deletePhysicConsultations(@PathVariable("refundId") Long refundId);

    @GetMapping("/refund/consultations/listByRefundIds")
    Response<List<Consultations>> listConsultationsByRefundIds(@RequestParam("refundIds") List<Long> refundIds);

    @GetMapping("/refund/consultations/listByRefundId/{refundId}")
    Response<List<Consultations>> listConsultationsByRefundId(@PathVariable("refundId") Long refundId);

}
